let ajaxTimes = 0;

// 定义公共的url
// const baseUrl="http://192.168.1.149:10130/";
// const baseUrl="http://192.168.1.144:20380/";
// const baseUrl = "http://192.168.1.114:10380/";
// const baseUrl = "http://192.168.1.31:10380/"
//  华为云h
// const baseUrl = "http://192.168.1.149:10133/"
// const baseUrl = "http://110.41.7.217:10130/"

// 预发布环境
// const baseUrl = "http://192.168.1.149:20130/"

// const baseUrl = "http://192.168.1.181:20380/"
const baseUrl = "http://192.168.1.181:10380/"
// const baseUrl = "http://192.168.1.144:20380/";
// const baseUrl="http://192.168.1.223:10380/";
// const baseUrl="http://117.48.217.16:10380/";
// const baseUrl="http://192.168.1.114:10380/";
// const baseUrl="http://192.168.1.72:10380/";
// const baseUrl="http://192.168.1.31:20130/";
// const baseUrl="https://erp.face-future.com/";
// const baseUrl="http://192.168.1.144:10380/";

// const baseUrl="http://arm920t.iicp.net:10131/";
// const baseUrl= "https://octiot.octlife.cn/"
// const baseUrl="http://192.168.1.22:10380/";

export {
	baseUrl
}

export const request = (params) => {
	let header = {
		...params.header
	};
	// if(params.url.includes("/my/")){
	//   header["Authorization"]=uni.getStorageSync("token");
	// } 
	header["openid"] = uni.getStorageSync("openid") || "oRekA4wN8O7hyfAlgdRNl4ughrm4";
	ajaxTimes++;
	uni.showLoading({
		title: "加载中",
		mask: true
	});

	return new Promise((resolve, reject) => {
		uni.request({
			...params,
			header: header,
			url: baseUrl + params.url,
			success: (result) => {
				//  console.log('我请求数据时的得到的返回信息',result.data);
				if (result.data.status === 0) {
					resolve(result.data);
				} else if (result.data.status === 403) {
					uni.showToast({
						title: result.data.description,
						icon: 'none',
						duration: 1000,
						success: (res) => {
							// uni.clearStorageSync()
							// uni.navigateTo({
							//   url: '/pages/login/login',
							// })
						},
					})
				} else {
					resolve(result.data);
				}
				ajaxTimes--;
				if (ajaxTimes === 0) {
					uni.hideLoading();
				}
			},
			fail: (err) => {
				ajaxTimes--;
				if (ajaxTimes === 0) {
					uni.hideLoading();
				}
				reject(err);

			},
			complete: () => {
				// 这里的代码是无论成功还是失败都会执行，暂时不用，因为要判断多项条件；
				// ajaxTimes--;
				// if(ajaxTimes===0){
				//   uni.hideLoading();
				// }
			}
		});
	})
}